cordova.define("mamp-plugin-media", function(require, exports, module) {
               
var exec = require('cordova/exec');
var cordovaMedia = require('cordova-plugin-media.Media');
var utils = require('cordova/utils');

var mediaObjects = {};

var Media = function(src, successCallback, errorCallback, statusCallback) {
    this.id = utils.createUUID();
    this.mediaInstance = new cordovaMedia(src, successCallback, errorCallback, statusCallback);
    mediaObjects[this.id] = this.mediaInstance;

};

Media.prototype.playAudioOptions = function() {
    return{
       userNativePlayer:false
    };
};
            
/*
 desc:调用系统相册选择图片
 callback:返回给JS时的回调方法
 limit:可选择张数，默认1张
 */
Media.prototype.playAudio = function(options) {
    var mediaInstance = mediaObjects[this.id];
	if (options && options.userNativePlayer) {
		exec(null, null, "MAMPMedia", "playAudioWithNativePlayer", [mediaInstance.src]);
	} else {
        mediaInstance.play(options);
	}
};

/*
 * desc:调用系统播放界面播放视频
 * src:视频地址，本地或在线url地址
 * successCallback:返回给JS时的回调方法
 * errorCallback:播放失败时的回调方法
 */
Media.prototype.playVideo = function(src, successCallback, errorCallback) {
    var mediaInstance = mediaObjects[this.id];
    exec(null, null, "MAMPMedia", "playVideoWithNativePlayer", [mediaInstance.src]);
};

/**
 * desc:停止播放指定音频
 */
Media.prototype.stop = function() {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.stop();
};

/**
 * desc:跳转到正在播放的音频的指定位置，
 * milliseconds:跳转到指定位置，单位为毫秒
 */
Media.prototype.seekTo = function(milliseconds) {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.seekTo(milliseconds);
};

/**
 * desc:暂停正在播放的音频
 */
Media.prototype.pause = function() {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.pause();
};

/**
 * desc:获取多媒体文件长度，单位为秒。值为-1时，说明无法获取长度。必须在已经播放，或已停止的对象上调用才有效
 */
Media.prototype.getDuration = function() {
    var mediaInstance = mediaObjects[this.id];
    return mediaInstance.getDuration();
};

/**
 * desc:获取当前播放进度，单位为秒
 * successCallback:返回给JS时的回调方法
 * errorCallback:播放失败时的回调方法
 */
Media.prototype.getCurrentPosition = function(success, fail) {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.getCurrentPosition(success, fail);
};

/**
 * desc:设置播放的音量
 * volume: 播放的音量，范围为 0.0 - 1.0
 */
Media.prototype.setVolume = function(volume) {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.setVolume(volume);
};

/**
 * desc:获取音频文件的振幅
 * successCallback:返回给JS时的回调方法
 * errorCallback:播放失败时的回调方法
 */
Media.prototype.getCurrentAmplitude = function(success, fail) {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.getCurrentAmplitude(success, fail);
};

/**
 * 开始录音
 */
Media.prototype.startRecord = function() {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.startRecord();
};

/**
 * 停止录音
 */
Media.prototype.stopRecord = function() {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.stopRecord();
};

/*
 desc:删除录音文件，必须在录音结束后调用
 */
Media.prototype.release = function() {
    var mediaInstance = mediaObjects[this.id];
    mediaInstance.release();
};
            
               
module.exports = Media;

});
